

@EXTERNAL FUNCTION getValue : DINT
    VAR_INPUT
        n : REF_TO STRING;
        t : REF_TO STRING;
        d : REF_TO STRING;
    END_VAR
END_FUNCTION


@EXTERNAL FUNCTION setValue : DINT
    VAR_INPUT
        n : REF_TO STRING;
        t : REF_TO STRING;
        d : REF_TO STRING;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION out : DINT
    VAR_INPUT
        t : REF_TO STRING;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION outW : DINT
    VAR_INPUT
        t : REF_TO WSTRING;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION outInt : DINT
    VAR_INPUT
        n : DINT;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION outFloat : DINT
    VAR_INPUT
        n : REAL;
    END_VAR
END_FUNCTION

TYPE _StructOfStudent: STRUCT
    name: STRING[255];
    age: INT;
    tt: DINT;
END_STRUCT END_TYPE


FUNCTION main : DINT
    VAR
        P : STRING := '';
        Q : WSTRING := "";
        int_array : ARRAY[0..2] OF DINT;
        bool_array : ARRAY[0..3] OF BOOL;
        R : CHAR := 'A';
		C : DINT := 0;
        StructOfStudent : _StructOfStudent;
		ty_date : DATE := 0;
		ty_time : TIME := 0;
		N : REAL := 0.0;
	END_VAR

    out(ADR('STRING Test:\n'));   
    out(ADR(P));
    setValue(ADR('P'),ADR('STRING'),ADR('wo shi fu zhi!'));
    out(ADR(P));
    out(ADR('=============================='));

    out(ADR('WSTRING Test:\n'));
    
    outW(ADR(Q));
    setValue(ADR('Q'),ADR('WSTRING'),ADR("2222Q hello st !!"));
    outW(ADR(Q));

	out(ADR('=============================='));	
	out(ADR('REAL Test:\n'));
	N := 3.1415;
    setValue(ADR('N'),ADR('REAL'),ADR(N));
    outFloat(N);
	
	out(ADR('=============================='));	
	out(ADR('TIME Test:\n'));
	ty_time := 1666072176;
	setValue(ADR('ty_time'),ADR('TIME'),ADR(ty_time));
	outInt(ty_time);
	
    out(ADR('=============================='));
    out(ADR('CHAR Test:\n'));
    outInt(R);
	R := 'N';
    setValue(ADR('R'),ADR('CHAR'),ADR(R));
    outInt(R);
    out(ADR('=============================='));
	
	out(ADR('DINT Test:\n'));
	C := 123456789;
    setValue(ADR('C'),ADR('DINT'),ADR(C));
    outInt(C);
    out(ADR('=============================='));

    out(ADR('DATE Test:\n'));
    ty_date := 1677000343;
    setValue(ADR('ty_date'),ADR('DATE'),ADR(ty_date));
    outInt(ty_date);
	out(ADR('=============================='));

    out(ADR('Array_INT Test:\n'));
    out(ADR('Array_INT setValue:'));
    int_array[0] := 6;
    int_array[1] := 106;
    setValue(ADR('Y'),ADR('Array_INT'),ADR(int_array));
    outInt(int_array[0]);
    outInt(int_array[1]);

    out(ADR('=============================='));

    out(ADR('Array_BOOL Test:\n'));
    out(ADR('Array_BOOL setValue:'));
    bool_array[0] := TRUE;
    bool_array[1] := FALSE;
	bool_array[2] := TRUE;
    setValue(ADR('Z'),ADR('Array_BOOL'),ADR(bool_array));

    outInt(bool_array[0]);
    outInt(bool_array[1]);
    out(ADR('=============================='));


    out(ADR('StructOfStudent Test:\n'));
    out(ADR('StructOfStudent setValue:\n'));
    StructOfStudent.name := 'hml';
    StructOfStudent.age := 16;
    StructOfStudent.tt := 100;
    setValue(ADR('StructOfStudent'),ADR('STRUCT'),ADR(StructOfStudent));
    out(ADR(StructOfStudent.name));
    outInt(StructOfStudent.age);
    outInt(StructOfStudent.tt);


END_FUNCTION
